package com.second.app.thread.notifydemo;

/**
 * @Author soul gao
 * @Date 2021/1/24 12:16
 * 努力学习 天天进步
 */
public class NotifyThread extends Thread {

    private Object lock;

    public NotifyThread(Object lock) {
        this.lock = lock;
    }
    private static final int NORMAL_VALUE = 10;
    private static final int SET_VALUE = 5;
    @Override
    public void run() {
        synchronized (lock) {
            System.out.println(Thread.currentThread().getName() + "：开始唤醒" + System.currentTimeMillis());
            lock.notify();
            for (int i = 0; i < NORMAL_VALUE; i++) {
                System.out.println(Thread.currentThread().getName()+":别急哦，等我循环执行完才能唤醒你," + (i + 1));
                if (i == SET_VALUE) {
                    System.out.println(Thread.currentThread().getName()+":好吧，不让你等了，早点让你醒吧," + (i + 1));
                    break;
                }
            }
            System.out.println(Thread.currentThread().getName() + "：结束唤醒" + System.currentTimeMillis());
        }
    }

}
